import { createApp } from 'vue'
import App from './App.vue'
import { default as router, setAdminRoute } from './router/index'
import store from './store/index'


// elementPlus
import ElementPlus from 'element-plus'
// 使ElementPlus的默认语言变为中文
import 'element-plus/theme-chalk/index.css'
import 'dayjs/locale/zh-cn'
// 新版本默认中文环境改成了这样
import zhCn from 'element-plus/es/locale/lang/zh-cn'

import "./util/dialog";

import "@/assets/iconfont/iconfont.css";

// 在页面卸载时将vuex里的信息保存到sessionStorage里
window.addEventListener("beforeunload", () => {
    sessionStorage.setItem("store", JSON.stringify(store.state));
});

// 页面加载时，将sessionStorage里面的数据加载进vuex中（利用vuex提供的replaceState函数）
const storeItem = sessionStorage.getItem("store");
if (storeItem) {
    store.replaceState(Object.assign({}, store.state, JSON.parse(storeItem)));

    // 重新调用setAdmin，方便加载数据
    setAdminRoute();
}


const app = createApp(App);
app.use(store).use(router).use(ElementPlus, { locale:zhCn });

app.mount('#app');